--[[
LuCI - Lua Configuration Interface

Copyright 2014 Steven Barth <emongxx@gmail.com>
Blog http://blog.emong.me

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

	http://www.apache.org/licenses/LICENSE-2.0

$Id$
]]--

local wa = require "luci.tools.webadmin"
local fs = require "nixio.fs"

m = Map("emongbwctrl", translate("网络带宽控制"),
	translate("简单的可用于多wan的粗暴的带宽控制。"))

function m.on_commit(self)
        luci.sys.exec("/etc/init.d/emongbwctrl restart")                                                   
end 

s = m:section(NamedSection, "config","emongbwctrl")
s.addremove = false
s.anonymous = false

e = s:option(Flag, "enable", translate("全局开关"))
e.rmempty = false


s = m:section(TypedSection, "ip-limit", translate("ip带宽控制"),translate("可以接受的地址形式：192.168.1.20,192.168.1.128/25,不能使用 192.168.1.2-192.168.1.30这种形式;带宽的单位为:KBit/s。"))
s.template = "cbi/tblsection"
s.anonymous = true
s.addremove = true
s.sortable  = true

enable = s:option(Flag, "enable", translate("启用"))
enable.default = 1
enable.optional = false
enable.rmempty = false

host = s:option(Value, "ip", translate("IP地址"))
host.rmempty = false
wa.cbi_add_knownips(host)

downbw = s:option(Value, "downbw", translate("下载带宽"))
downbw.default = 2000
downbw.rmempty = false

upbw = s:option(Value, "upbw", translate("上行带宽"))
upbw.default = 500
upbw.rmempty = false

return m
